---
title: Listen to location
description: How to listen to your user's location
---

# Listen to Location

To listen to the location of the user, you can simply use

```dart
Stream<LocationData> onLocationChanged({bool inBackground = false})
```

The stream will use the global settings for location tracking.
You can set the settings with [`setLocationSettings`](/features/settings).

If you change settings while listening to the location, the stream will be updated with the new settings (you can only have onn global settings active at the same time).

Don't forget to **cancel the stream** when you don't need it anymore. Otherwise the location will keep being tracked.

If you set the boolean `inBackground` to true, you will have receive background location notifications. It works only if the app is not killed.
On Android, listening to background location will trigger a notification that you can control with [`updateBackgroundNotification`](/features/notification).

## Examples

### Listening to location in the background

The notification will only appear on Android

```dart
_locationSubscription = onLocationChanged(inBackground: _inBackground)
    .listen((LocationData currentLocation) async {
        await updateBackgroundNotification(
            subtitle:
                'Location: ${currentLocation.latitude}, ${currentLocation.longitude}',
            onTapBringToFront: true,
        );
    }
);

...

_locationSubscription?.cancel();
```
